import App from './App'

// #ifndef VUE3
import Vue from 'vue'
import uView from '@/uni_modules/uview-ui'
Vue.use(uView)
import http from '@/api/request.js'
//Vue.prototype.$http = http
import axios from 'axios'
Vue.use(axios)
Vue.prototype.$axios = axios
import highlight from 'highlight.js';
Vue.use(highlight)
import ws from 'api/webSocket.js'
Vue.prototype.$ws = ws
import store from './store'
import tabbar from 'pages/tabbar/tabbar.vue'
//import './interceptor.js'
import commonNavbar from 'pages/components/commonNavbar.vue'
import commentsArea from 'pages/components/commentsArea.vue'
import userThoughts from 'pages/components/userHomeFrames/userThoughts.vue'
import userArticles from 'pages/components/userHomeFrames/userArticles.vue'
import userPostList from 'pages/components/userHomeFrames/userPostList.vue'
import userExprience from 'pages/components/userHomeFrames/userExprience.vue'
import userCollections from 'pages/components/userHomeFrames/userCollections.vue'
import thoughtsDetail from 'pages/components/userHomeFrames/thoughtsDetail.vue'
import commentsList from 'pages/components/commentsList.vue'
import concernsAndFans from 'pages/components/userHomeFrames/concernsAndFans.vue'
import changeOwnInfo from 'pages/components/userHomeFrames/changeOwnInfo.vue'
import postDetail from 'pages/components/postDetail.vue'
import Home from 'pages/components/userHomeFrames/Home.vue'
import forum from 'pages/components/forum.vue'
import team from 'pages/components/team.vue'
import message from 'pages/components/message.vue'
import square from 'pages/components/square.vue'
import aboutMe from 'pages/components/aboutMe.vue'
import otherUserHome from 'pages/components/userHomeFrames/otherUserHome.vue'
import myNav from 'pages/components/myNav.vue'
import activity from 'pages/components/aboutTeam/activity.vue'
import codeTeam from 'pages/components/aboutTeam/codeTeam.vue'
import competition from 'pages/components/aboutTeam/competiton.vue'
import articleDetails from 'pages/components/articleDetails.vue'
import mine from 'pages/components/aboutTeam/optionsPage/mine.vue'
import publish from 'pages/components/aboutTeam/optionsPage/pubish.vue'
import updateTeam from 'pages/components/aboutTeam/optionsPage/updateTeam.vue'
import myjoin from 'pages/components/aboutTeam/optionsPage/myjoin.vue'
import publishActivity from "pages/components/aboutTeam/optionsPage/publishActivity.vue"
import chatPage from 'pages/components/chatPage.vue'
Vue.component('chatPage', chatPage)
Vue.component('publishActivity',publishActivity)
Vue.component('myjoin',myjoin)
Vue.component('mine',mine)
Vue.component('publish',publish)
Vue.component('articleDetails',articleDetails)
Vue.component('activity', activity)
Vue.component('codeTeam',codeTeam)
Vue.component('competition',competition)
Vue.component('myNav', myNav)
Vue.component('forum',forum)
Vue.component('team',team)
Vue.component('message',message)
Vue.component('square',square)
Vue.component('aboutMe',aboutMe)
Vue.component('Home',Home)
Vue.component('postDetail', postDetail)
Vue.component('tab-bar',tabbar)
Vue.component('commonNavbar',commonNavbar)
Vue.component('commentsArea',commentsArea)
Vue.component('commonNavbar', commonNavbar)
Vue.component('commentsArea', commentsArea)
Vue.component('userThoughts', userThoughts)
Vue.component('userArticles', userArticles)
Vue.component('userPostList',userPostList)
Vue.component('userExprience', userExprience)
Vue.component('userCollections', userCollections)
Vue.component('thoughtsDetail', thoughtsDetail)
Vue.component('commentsList',commentsList)
Vue.component('concernsAndFans',concernsAndFans)
Vue.component('otherUserHome',otherUserHome)
Vue.component('changeOwnInfo',changeOwnInfo)
Vue.component('updateTeam', updateTeam)
Vue.config.productionTip = false
Vue.prototype.$store = store
App.mpType = 'app'

// 如此配置即可
uni.$u.config.unit = 'rpx'
//封装成一个指令
Vue.directive('highlight', (el) => {
  let blocks = el.querySelectorAll('pre code')
  blocks.forEach((block) => {
    highlight.highlightBlock(block)
  })
})

// 添加axios请求拦截器
/*
axios.interceptors.request.use(
    config => {
        // do something before request is sent

        if (store.getters.token) {
             config.headers['X-Token'] = getToken()
        }
        return config
    },
    error => {
        // do something with request error
        console.log(error) // for debug
        return Promise.reject(error)
    }
)
*/

try {
  function isPromise(obj) {
    return (
      !!obj &&
      (typeof obj === "object" || typeof obj === "function") &&
      typeof obj.then === "function"
    );
  }

  // 统一 vue2 API Promise 化返回格式与 vue3 保持一致
  uni.addInterceptor({
    returnValue(res) {
      if (!isPromise(res)) {
        return res;
      }
      return new Promise((resolve, reject) => {
        res.then((res) => {
          if (res[0]) {
            reject(res[0]);
          } else {
            resolve(res[1]);
          }
        });
      });
    },
  });
} catch (error) { }

const app = new Vue({
  ...App,
  store
})
app.$mount()
// #endif

// #ifdef VUE3
import { createSSRApp } from 'vue'
import axios from 'axios'
export function createApp() {
  const app = createSSRApp(App)
  return {
    app,
  }
}
// #endif